import QRCode from 'qrcode2'
export default {
	data () {
		return {
			options:[
				{
				    value: '1',
				    label: '行情卖料'
				},
				{
				    value: '2',
				    label: '灵活寄存'
				},
				{
				    value: '3',
				    label: '定价卖料'
				},
			],
			isShowUplodeImg:false,
			rowData:{},
			imgUrlList1:[],
			imgUrlList2:[]
		}
	},
	watch:{
		
	},
	computed: {
	    
	},
	methods: {
		delImg(el,i){
			this.$post('/uplodeFile/delH5Img',{id:el.id},res=>{
				if(el.road==1){
					this.imgUrlList1.splice(i,1)
				}else{
					this.imgUrlList2.splice(i,1)
				}
				
			})
		},
		closeUplodeImg(){
			clearInterval(this.timerName)
		},
		uplodeImg(scope){
			if(!this.form.ttype) return this.$message.error('请选择入库类型')
			let type
			if(this.form.ttype==3){  // 1 行情卖料 2灵活寄存 3 定价卖料 
				type = 1 
			}else{
				type = 2
			}
			
			this.rowData = scope.row
			this.isShowUplodeImg = true
			let token = sessionStorage.getItem('token')
			
			let url1 = `${this.$baseUrl}/static/vue/uplodeImg.html?token=${token}&type=${type}&oid=${scope.row.pao_id}&road=1`
		    
			let url2 = `${this.$baseUrl}/static/vue/uplodeImg.html?token=${token}&type=${type}&oid=${scope.row.pao_id}&road=2`
					   
			setTimeout(()=>{
				let qrcode1 = new QRCode('d1',{
				  text:url1
				})
			},100)
			
			setTimeout(()=>{
				let qrcode1 = new QRCode('d2',{
				  text:url2
				})
			},100)
			
			let params = {
				o_id:scope.row.pao_id
			}
			this.$post('/uplodeFile/lodeH5ImgList',params,res=>{
				let item = res.data.data
				this.imgUrlList1 = item.filter((el)=>{
					return el.road==1
				})
				this.imgUrlList2 = item.filter((el)=>{
					return el.road==2
				})
			})
			this.timerName = setInterval(()=>{
				let params = {
					o_id:scope.row.pao_id
				}
				this.$post('/uplodeFile/lodeH5ImgList',params,res=>{
					let item = res.data.data
					this.imgUrlList1 = item.filter((el)=>{
						return el.road==1
					})
					this.imgUrlList2 = item.filter((el)=>{
						return el.road==2
					})
				})
			},1000)
			
			
		},
		delRow(scope){
			let index = scope.$index
			this.list.splice(index,1)
			this.isShowSelectGoods = false
			this.$nextTick(()=>{
				this.isShowSelectGoods = true
			})
		},
		addBtn(){
			let obj = {
				pao_id:'',
				id:undefined,
			    show_goods_name:"", // 收货商品名称
				pay_money:'',  // 实际结算金额
				show_weight:"", // 实收重量
				show_price:'', // 实收重量
				remark:"",
			}
			this.list.push(obj)
			
			this.isOutDep = false
			this.isShowSelectGoods = false
			this.$nextTick(()=>{
				this.isShowSelectGoods = true
			})
		},
		initData2(res){
			this.list = []
			for(let item of res){
				this.list.push(
					{
						pao_id:item.id,
						id:undefined,
						show_goods_name:"", // 收货商品名称
						pay_money:'',  // 实际结算金额
						show_weight:"", // 实收重量
						show_price:'', // 实收重量
						remark:"",
					}
				)
				for(let i in this.form){
					this.form[i] = item[i]
				}
				this.form.supplier = item.user_info.name + '_' + item.user_info.phone
				
				let html =
				`<div >
					<div class="flex">
						<div style="width: 80px;text-align: right;">
						  ID：
						</div>
						<div style="width: 200px;">
							${item.id}
						</div>
					</div>
					<div class="flex">
						<div style="width: 80px;text-align: right;">
						  报单日期：
						</div>
						<div style="width: 200px;">
							${item.add_time}
						</div>
					</div>
					<div class="flex">
						<div style="width: 80px;text-align: right;">
						  供应商：
						</div>
						<div style="width: 200px;">
							${this.form.supplier}
						</div>
					</div>
					<div class="flex">
						<div style="width: 80px;text-align: right;">
						  报单品类：
						</div>
						<div style="width: 200px;">
							${item.goods_name}
						</div>
					</div>
					<div class="flex">
						<div style="width: 80px;text-align: right;">
						  报单克重：
						</div>
						<div style="width: 200px;">
							${item.pre_weight}
						</div>
					</div>
					<div class="flex" style="color:red">
						<div style="width: 80px;text-align: right;">
						  发货单1：
						</div>
						<div style="width: 200px;">
							${item.delivery_number}<span>(${item.pre_weight})</span>
						</div>
					</div>
				</div>`
				setTimeout(()=>{
					this.$notify({
					         title: '报单信息',
							 dangerouslyUseHTMLString:true,
					         message: html,
					         duration: 0
					});
				},500)
				
			}
			
		},
		initData1(res){
			this.list = []
			let result3 = res.result3
			let result1 = res.result1
			
			for(let i in this.form){
				this.form[i] = result3[i]
			}
			this.form.supplier = result3.user_info.name + '_' + result3.user_info.phone
			
			
			let delivery_number_html = ''
			result1.forEach((item,i)=>{
				
				if(item.status == 3){
					delivery_number_html+=
					`
						<div class="flex">
							<div style="width: 80px;text-align: right;">
							  发货单${i+1}：
							</div>
							<div style="width: 200px;">
								${item.delivery_number || '跑腿'}(${item.pre_weight})
							</div>
							-------------${item.id}
						</div>
					`
				}else{
					if(!item.delivery_number){
						delivery_number_html+=
						`
							<div class="flex">
								<div style="width: 80px;text-align: right;">
								  发货单${i+1}：
								</div>
								<div style="width: 200px;">
									跑腿(${item.pre_weight})
									—— ${item.id}
								</div>
								
							</div>
						`
					}else{
						if(item.delivery_number == this.delivery_number){
							delivery_number_html+=
							`
								<div class="flex" style="color:red">
									<div style="width: 80px;text-align: right;">
									  发货单${i+1}：
									</div>
									<div style="width: 200px;">
										${item.delivery_number}(${item.pre_weight})
										—— ${item.id}
									</div>
									
								</div>
							`
						}else{
							delivery_number_html+=
							`
								<div class="flex">
									<div style="width: 80px;text-align: right;">
									  发货单${i+1}：
									</div>
									<div style="width: 200px;">
										${item.delivery_number}(${item.pre_weight})
										—— ${item.id}
									</div>
									
								</div>
							`
						}
						
					}
					
					this.list.push(
						{
							pao_id:item.id,
							id:undefined,
							show_goods_name:"", // 收货商品名称
							pay_money:'',  // 实际结算金额
							show_weight:"", // 实收重量
							show_price:'', // 实收重量
							remark:"",
						}
					)
				}
				
			})
			
			let html = 
		    `<div >
				<div class="flex">
					<div style="width: 80px;text-align: right;">
					  报单日期：
					</div>
					<div style="width: 200px;">
						${result3.add_time}
					</div>
				</div>
				<div class="flex">
					<div style="width: 80px;text-align: right;">
					  供应商：
					</div>
					<div style="width: 200px;">
						${this.form.supplier}
					</div>
				</div>
				<div class="flex">
					<div style="width: 80px;text-align: right;">
					  定价品类：
					</div>
					<div style="width: 200px;">
						${this.form.goods_name}
					</div>
				</div>
				${delivery_number_html}
			</div>`
			this.$notify({
			         title: '报单信息',
					 dangerouslyUseHTMLString:true,
			         message: html,
			         duration: 0
			});
			
		},
		
		delLastList(){
		   let len = this.list.length
		   this.list.splice(len-1,1)
		},
	}
}